package com.peanut.controller;

import com.peanut.common.Result;
import com.peanut.service.TabItemService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.Map;


@RestController
@RequestMapping("/search")
public class EsController {

    @Resource
    private TabItemService tabItemService;

    @PostMapping("/test")
    public Result test(){
        boolean b = tabItemService.test();
        return Result.OK().setData(b);
    }

    @PostMapping("/participle")
    @ApiOperation(value = "商品的模糊(分词搜索)")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "title",value = "shan",paramType = "query",required = true)
    )
    public Result searchInfo(@RequestParam("title") String title,
                             @RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize){
        Map<String, Object> map = tabItemService.selectInfo(title,pageNum,pageSize);

        return Result.OK().setData(map);
    }

    @PostMapping("/selectCondition")
    @ApiOperation(value = "车辆的条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemRegisteredDate",value = "上牌时间",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemRoadHaul",value = "行驶里程",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemEvaluate",value = "估价",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemValidate",value = "验车地址",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemEmissionStandard",value = "排放标准",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemCity",value = "上牌城市",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemPrice",value = "当前售价",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemNewPrice",value = "新车含税价",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemChangeNumber",value = "过户次数",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemDisplacement",value = "排量",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemAnnualInspectionDate",value = "年检到期",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemFunction",value = "使用性质",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemMliftaDate",value = "交强险到期",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemColor",value = "车身颜色",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemProductionDate",value = "出厂日期",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemOptions",value = "车源号",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemKeyNum",value = "钥匙数量",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemRank",value = "车辆级别",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemSeating",value = "座位数",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemCarAge",value = "车龄",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemLocationLicensePlate",value = "车牌所在地",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemEnergySources",value = "能源类型",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemGearbox",value = "变速箱",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemAirCylinder",value = "气缸数量",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemAirInlet",value = "进气方式",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemDrivingType",value = "驱动类型",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemContry",value = "国别",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemYearType",value = "年款",paramType = "query",required = false),
            @ApiImplicitParam(name = "itemHits",value = "点击量",paramType = "query",required = false),
    })
    public Result selectCondition(@RequestParam(required = false) Date itemRegisteredDate, @RequestParam(required = false) Long itemRoadHaul,
                                  @RequestParam(required = false) String itemEvaluate, @RequestParam(required = false) String itemValidate,
                                  @RequestParam(required = false) Integer itemEmissionStandard, @RequestParam(required = false) Integer itemCity,
                                  @RequestParam(required = false) BigDecimal itemPrice, @RequestParam(required = false) BigDecimal itemNewPrice,
                                  @RequestParam(required = false) Integer itemChangeNumber, @RequestParam(required = false) BigDecimal itemDisplacement,
                                  @RequestParam(required = false) Date itemAnnualInspectionDate, @RequestParam(required = false) String itemFunction,
                                  @RequestParam(required = false) Date itemMliftaDate, @RequestParam(required = false) Integer itemColor,
                                  @RequestParam(required = false) Date itemProductionDate, @RequestParam(required = false) Long itemOptions,
                                  @RequestParam(required = false) Integer itemKeyNum, @RequestParam(required = false) Integer itemRank,
                                  @RequestParam(required = false) Integer itemSeating, @RequestParam(required = false) Long itemCarAge,
                                  @RequestParam(required = false) Integer itemLocationLicensePlate, @RequestParam(required = false) Integer itemEnergySources,
                                  @RequestParam(required = false) Integer itemGearbox, @RequestParam(required = false) Integer itemAirCylinder,
                                  @RequestParam(required = false) Integer itemAirInlet, @RequestParam(required = false) Integer itemDrivingType,
                                  @RequestParam(required = false) Integer itemContry, @RequestParam(required = false) Integer itemYearType,
                                  @RequestParam(required = false) Long itemHits
                                  ){
        Map<String, Object> map = tabItemService.selectCondition(itemRegisteredDate,itemRoadHaul,itemEvaluate,itemValidate,itemEmissionStandard,itemCity,itemPrice,
                                                                 itemNewPrice,itemChangeNumber,itemDisplacement,itemAnnualInspectionDate,itemFunction,itemMliftaDate,
                                                                 itemColor,itemProductionDate,itemOptions,itemKeyNum,itemRank,itemSeating,itemCarAge,itemLocationLicensePlate,
                                                                 itemEnergySources,itemGearbox,itemAirCylinder,itemAirInlet,itemDrivingType,itemContry,itemYearType,itemHits);
        return Result.OK().setData(map);
    }
}
